import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

/**
 * @Author wonghiu
 * @Date 2021/8/17 13:06
 * @Version 1.0.1
 */
public class fanShe {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException, ClassNotFoundException {
        Person zhangsan = new Person(1, "zhangsan");
//        Class<? extends Person> aClass = zhangsan.getClass();
//
//        Field name = aClass.getDeclaredField("name");
//        name.setAccessible(true);
//        name.set(zhangsan,"lisi");
//        aClass.getConstructor().newInstance();
//        System.out.println(zhangsan);
        Class<?> person = Class.forName("Person");
        Object wangwu = person.getConstructor(int.class, String.class).newInstance(1, "wangwu");
        System.out.println(wangwu);
    }
}
class Person{
    private int age;
    private String name;

    public Person(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
